package com.example.demo.repository;

import com.example.demo.pojo.Transaction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface TransactionRepository extends JpaRepository<Transaction, Integer> {

    @Query(value = "select * from transaction limit ?,?", nativeQuery = true)
    List<Transaction> findAll(int start, int number);

    @Query(value = "select * from transaction where t_user=? limit ?,?", nativeQuery = true)
    List<Transaction> findByUserId(Integer u_id, int start, int number);

    @Query(value = "select * from transaction where t_id=?", nativeQuery = true)
    Transaction findByTransactionId(Integer t_id);

    @Query(value = "select * from transaction where t_amount between ? and ?", nativeQuery = true)
    List<Transaction> findByTransactionAmount(BigDecimal low, BigDecimal high);

    @Query(value = "select * from transaction where t_time between ? and ?", nativeQuery = true)
    List<Transaction> findByTransactionTime(Date early, Date late);

    @Query(value = "select count(*) from transaction", nativeQuery = true)
    Integer countAll();

    @Query(value = "select count(*) from transaction where t_user=?", nativeQuery = true)
    Integer countAllByUserId(Integer u_id);
}
